<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{$shop['companyname']}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <script src="{MODULE_URL}template/resources/js/jquery-2.1.1.min.js"></script>
    <link href="{MODULE_URL}template/resources/js/bootstrap.min.css" rel="stylesheet">
    <script src="{MODULE_URL}template/resources/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="{MODULE_URL}template/resources/layui/css/layui.css" media="all">
    <script src="{MODULE_URL}template/resources/layui/layui.js"></script>
    <link href="{MODULE_URL}template/mobile/default/base.css" rel="stylesheet">
    <script src="{MODULE_URL}template/resources/js/swiper.min.js"></script>
    <link href="{MODULE_URL}template/resources/js/swiper.min.css" rel="stylesheet">
    <script src="{MODULE_URL}template/resources/js/let.js"></script>
    <script src="{MODULE_URL}template/resources/js/webcommon.js"></script>
    <script src="{MODULE_URL}template/resources/js/jquery.fly.min.js"></script>
    <script src="{MODULE_URL}template/resources/js/fastclick.min.js"></script>

    <style>
        html,body{height:100%;overflow:hidden;font-size:14px;}
        body{ margin:0; background:#EEE;background:-webkit-radial-gradient(#E89535, #D96512);background: radial-gradient(#E89535, #D96512);}
        .loginbox{margin:0 auto;width:90%;background:rgba(255,255,255,0.4); padding:20px; border-radius:4px; position:relative;}
        .loginbox p{ margin-bottom:10px;}
        .loginbox p input{text-align:center; height:40px; line-height:40px;}
        .loginbox p button{ height:40px; line-height:40px; font-size:18px}
        .logoutbtn{ position:absolute; color:#FFF; top:5px; right:5px; font-size:18px}

        .modal_selectpersonbox2{ padding:15px;}
        .moad_inputbox{ margin-bottom:15px; position:relative;}
        .moad_inputbox input{ border:none; border:1px solid #CCC;border-radius:4px; text-align:right;font-family:微软雅黑;font-size:25px;font-weight:bold;color:rgb(102, 102,102); width:100%; padding:5px 52px 5px 0}
        .moad_inputbox span{ position:absolute; right:15px; top:10px; line-height:25px;font-size:25px;color:#CCC}
        .modal_selectpersonbox2 .modal_body{ padding:0;overflow:hidden}
        .modal_selectpersonbox2 .modal_body a{display:block;line-height:42px;border-radius:4px;background:#FFF;font-size:25px;text-align:center;font-family:Arial; margin-right:5px; border:1px solid #CCC; overflow:hidden}
        .modal_selectpersonbox2 .modal_body .layui-row{ margin-bottom:8px;}
        .modal_selectpersonbox2 .modal_body a.btnsure{ position:absolute; height:150px; width:84px;}


        .modal_selectpersonbox{ padding:15px;}
        .moad_inputbox{ margin-bottom:15px; position:relative;}
        .moad_inputbox input{ border:none; border:1px solid #CCC;border-radius:4px; text-align:right;font-family:微软雅黑;font-size:25px;font-weight:bold;color:rgb(102, 102,102); width:100%; padding:5px 0px 5px 0}
        .moad_inputbox span{ position:absolute; right:15px; top:10px; line-height:25px;font-size:25px;color:#CCC}
        .modal_selectpersonbox .modal_body{ padding:0;overflow:hidden}
        .modal_selectpersonbox .modal_body a{display:block;line-height:42px;border-radius:4px;background:#FFF;font-size:25px;text-align:center;font-family:Arial; margin-right:5px; border:1px solid #CCC; overflow:hidden}
        .modal_selectpersonbox .modal_body .layui-row{ margin-bottom:8px;}
        .modal_selectpersonbox .modal_body a.btnsure{ position:absolute; height:150px; width:84px;}

        .orderbox{width:100%;background:#EEE; margin-top: 50px; height: 100%;position: relative;}
        .mainmenu{position:absolute;top:0;bottom:0;left:0;width:80px;overflow:hidden;background:#393D49;text-align:center;display:-webkit-box;display:-webkit-flex;display:flex; -webkit-box-pack:center;-webkit-justify-content:center;justify-content:center;-webkit-box-align:center;-webkit-align-items:center; align-items:center;}
        .mainmenu ul.mainmenubtn{ width:100%;margin-right:1px;}
        .mainmenu ul.mainmenubtn li{ text-align:center; margin-bottom:20px; padding:10px 0; width:100%;}
        .mainmenu ul.mainmenubtn li p i{ font-size:26px; color:#EEE}
        .mainmenu ul.mainmenubtn li h3{ margin-top:5px; text-align:center; font-size:14px; color:#EEE;}
        .mainmenu ul.mainmenubtn li.isselect{ background:#FFF;}
        .mainmenu ul.mainmenubtn li.isselect p i{color:#333}
        .mainmenu ul.mainmenubtn li.isselect h3{color:#333;}
        .menulogo{ position:absolute; z-index:1; left:10px; bottom:20px; width:60px;}

        .pcatelist,.pcatelist li{ list-style: none;}
        .pcatelist{ background: #EEE; height: 100%;}
        .pcatelist li{ border-bottom:1px solid #FFF; padding: 10px; position: relative}
        .pcatelist li .showallnum{position: absolute; top: 2px;right: 2px;}
        .pcatelist li.isselect{ background: #FFF;}
        .goodlist,.goodlist li{ list-style: none;}
        .goodlist{margin:10px; overflow-y:scroll;}
        .goodlist li{ clear: both;border-bottom:1px solid #EEE;margin-bottom: 10px;}
        .goodlist li .img{width:68px; float: left;margin-right: 5px;}
        .goodlist li .img img{height:68px;width:68px;border-radius:4px;}
        .goodlist li .info {margin-left: 75px;}
        .goodlist li .info h3{ font-size: 14px; font-weight: bolder; margin-bottom: 5px;}
        .goodlist li .info .other{color: #666; margin-bottom: 5px; font-size: 12px;}
        .gprice{color: #F60;}
        .goodlist li .info a{font-size:14px; line-height:18px; border: 1px solid #2395FF;width:20px;height:20px; display:inline-block; border-radius: 100%;text-align: center; font-weight: bolder}
        .goodlist li .info a.reduce{ background: #FFF;color: #000;}
        .goodlist li .info a.reduce:active{background: #2395FF;color: #FFF;}
        .goodlist li .info a.add{ background:#2395FF;color: #FFF;}
        .goodlist li .info a.add:active{background:#FFF;color: #000;}
        .goodlist li .info input{ background: none; border: none; width:30px; text-align: center}
        footer{height:50px; line-height:50px;text-align:center;color:#FFF;background:rgba(0,0,0,0.6); position:absolute; z-index: 10; bottom:0;left: 0;right:0;}
        footer .carticon{ width: 100%; height:50px; position: relative;}
        footer .cart{border: 4px solid #666; background: #333; text-align: center; border-radius: 100%; width: 60px; height: 60px; line-height:50px; font-size:20px; position: absolute; bottom:10px;left: 20px; color:#2395FF;}
        .totalprice{ font-size: 16px;color: #FFF; text-indent: 10px; font-weight: bolder}
        footer .showallnum{position: absolute;bottom:45px;left:55px;}

        .showbox{ background: #FFF;}
        .showbox h3{ font-size: 14px; font-weight: bolder; margin-bottom: 5px;}
        .showbox p{ margin: 5px 0;}
        .showbox .gprice{ font-family: Arial; font-size: 14px; font-weight: bolder;color: #F60;}
        .showbox a{ background:#2395FF;color: #FFF; border-radius:10px; padding: 3px 5px;}
        .shopcartbox{position: absolute;left:0;right: 0;top: 0;bottom: 0; z-index: 2;}
        .shopcartbox .masker{position: absolute;left:0;right: 0;top: 0;bottom: 0; z-index: 3; background: rgba(0,0,0,0.6);}
        .shopcartbox .shopcart{background: #FFF;position: absolute; z-index:4;bottom:50px;left:0;right: 0;}
        .shopcart_top{ background: #DDD;color: #000; padding: 10px;}

        .menulist{overflow-y: scroll}
        .menulist,.menulist li{ list-style: none;}
        .menulist li{ padding: 5px 10px; background: #FFF; border-bottom: 2px solid #EEE;display:-webkit-box;display:-webkit-flex;display:flex;-webkit-box-align:center;-webkit-align-items:center;align-items:center;height:50px;}
        .menulist li div[class^='layui-col-'] p{width:100%; font-size: 12px; color: #999}
        .menulist li a{font-size:14px; line-height:18px; border: 1px solid #2395FF;width:20px;height:20px; display:inline-block; border-radius: 100%;text-align: center; font-weight: bolder}
        .menulist li a.reduce{ background: #FFF;color: #000;}
        .menulist li a.reduce:active{background: #2395FF;color: #FFF;}
        .menulist li a.add{ background:#2395FF;color: #FFF;}
        .menulist li a.add:active{background:#FFF;color: #000;}
        .menulist li a:hover,.menulist li a:active,.menulist li a:visited{text-decoration: none;}
        .menulist li input{ background: none; border: none; width:30px; text-align: center}
        .header{height:50px; line-height:50px;text-align:center;color:#FFF;background: #5FB878; position: absolute; z-index: 2; top:0;left: 0;right:0;}
        footer{height:40px;line-height:40px;text-align:center;color:#FFF;background:#5FB878;position:absolute; z-index: 2; bottom:0;left: 0;right:0;}
    </style>
</head>
<body>
{if $operation=="login"}
<section class="loginbox">
    <form id="loginform" action="" method="post" class="layui-form">
        <p class="text-center"><img src="{php echo tomedia($cfg['logo'])}" style="max-width:300px; max-height:200px; margin-bottom:30px;width:90%"/></p>
        <p><input type="password" name="pass" lay-verify="required"  id="mpassword" placeholder="请输入密码" class="layui-input"/></p>
        <p><button type="button" class="layui-btn" lay-submit lay-filter="formDemo" style="width:100%;">登陆</button></p>
    </form>
</section>
<script language="javascript">
    $(function() {
        FastClick.attach(document.body);
    });
    layui.use(['layer', 'element','form'], function(){
        var layer = layui.layer
                ,element = layui.element
                ,form = layui.form;

        var _w=$(window).width();
        var _h=$(window).height();
        var __h=$(".loginbox").height();
        $(".loginbox").css("margin-top",(_h-__h)*0.5);

        form.on('submit(formDemo)', function(data){
            var password=$("#mpassword").val();
            if(password.length<4){
                layer.msg("请输入密码",{icon:2,time: 2000});
                return false;
            }
            var index2=layer.load(1, {shade: [0.1,'#fff']});
            $.post("{php echo $this->createMobileUrl('ajax',array('op'=>'login'))}",{password:password},function(returnstr){
                console.log(returnstr);
                var result=eval("("+returnstr+")");
                if(result.success){
                    location.reload();
                }else{
                    layer.close(index2);
                    layer.msg(result.msg,{icon:2,time: 2000});
                    return false;
                }
            })
            return false;
        });
    });
</script>
{else}
<input type="hidden" name="sub_person" id="sub_person"/>
<input type="hidden" name="sub_tid" id="sub_tid"/>
<input type="hidden" name="sub_userid" id="sub_userid"/>
<input type="hidden" name="sub_orderid" id="sub_orderid"/>
<section class="loginbox">
    <form id="loginform" action="" method="post" class="layui-form">
        <div class="logoutbtn" onClick="fun_mainFun(4)"><i class="fa fa-remove"></i></div>
        <p class="text-center"><img src="{php echo tomedia($cfg['logo'])}" style="max-width:300px; max-height:200px; margin-bottom:30px"/></p>
        <p><button type="button" class="layui-btn layui-btn-primary" style="width:100%;font-weight:bold;color:#009688">{$shop['companyname']}</button></p>
        <p><button type="button" class="layui-btn layui-btn-primary" style="width:100%;font-weight:bold;color:#009688">服务员：{$userOper['realname']}</button></p>
        <p><button type="button" class="layui-btn layui-btn-primary" id="tablebtn" onClick="mdl_selecttable()" style="width:100%;">选择餐桌</button></p>
        <p><button type="button" class="layui-btn" lay-submit lay-filter="formDemo" style="width:100%;">开台</button></p>
    </form>
</section>

<div class="header layui-row" style="display:none;">
    <div class="layui-col-xs2" onClick="fun_mainFun(3)"><i class="fa fa-home"></i></div>
    <div class="layui-col-xs8 title">点餐</div>
    <div class="layui-col-xs2" onClick="fun_mainFun(2)"><i class="fa fa-user"></i></div>
</div>

<section class="orderbox layui-row">
    <div class="layui-col-xs3">
        <ul class="pcatelist">
            {loop $goodpcatelist $row}
            <li pcate="{$row['id']}" onclick="fun_selectgoodpcate({$row['id']})">{$row['title']}</li>
            {/loop}
        </ul>
    </div>
    <div class="layui-col-xs9">
        <ul class="goodlist">

        </ul>
    </div>
</section>
<footer class="layui-row" style="display:none;">
    <div class="layui-col-xs3"><div class="carticon" onclick="showCart(1)"><div class="cart"><i class="fa fa-folder-close"></i></div></div></div>
    <div class="layui-col-xs6 text-left totalprice">￥0.00</div>
    <div class="layui-col-xs3" style="background:#5FB878" onclick="submitOrder()">下单</div>
</footer>
<style>
    .shopcartbox{position: absolute;left:0;right: 0;top: 0;bottom: 0;z-index: 3;}
    .shopcartbox .masker{position: absolute;left:0;right: 0;top: 0;bottom: 0; z-index: 4; background: rgba(0,0,0,0.6);}
    .shopcartbox .shopcart{background: #FFF;position: absolute; z-index:5;bottom:50px;left:0;right: 0;}
    .shopcart_top{ background: #DDD;color: #000; padding: 10px;}
    .menulist{overflow-y: scroll}
    .menulist,.menulist li{ list-style: none;}
    .menulist li{ padding: 5px 10px; background: #FFF; border-bottom: 2px solid #EEE;display:-webkit-box;display:-webkit-flex;display:flex;-webkit-box-align:center;-webkit-align-items:center;align-items:center;height:50px;}
    .menulist li div[class^='layui-col-'] p{width:100%; font-size: 12px; color: #999}
    .menulist li a{font-size:14px; line-height:18px; border: 1px solid #2395FF;width:20px;height:20px; display:inline-block; border-radius: 100%;text-align: center; font-weight: bolder}
    .menulist li a.reduce{ background: #FFF;color: #000;}
    .menulist li a.reduce:active{background: #2395FF;color: #FFF;}
    .menulist li a.add{ background:#2395FF;color: #FFF;}
    .menulist li a.add:active{background:#FFF;color: #000;}
    .menulist li a:hover,.menulist li a:active,.menulist li a:visited{text-decoration: none;}
    .menulist li input{ background: none; border: none; width:30px; text-align: center}
</style>
<section class="shopcartbox" style="display: none;">
    <div class="masker" onclick="showCart(0)"></div>
    <DIV class="shopcart">
        <div class="shopcart_top">已选商品<span class="pull-right" onclick="clearOrder()">清空</span></div>
        <ul class="menulist">

        </ul>
    </DIV>
</section>

<!--人数选择-->
<div class="modal_selectperson" style="display:none">
    <div class="modal_selectpersonbox">
        <div class="moad_inputbox">
            <input type="text" id="moadConterInput"  maxlength="2" value="0" />
        </div>
        <div class="modal_body">
            <div class="layui-row">
                <div class="layui-col-xs6"><button type="button" id="modal_selectpersonclosebtn" class="layui-btn layui-btn-big" style="width:98%; background:#FFF; color:#333; border:1px solid #CCC;">关闭</button></div>
                <div class="layui-col-xs6"><button type="button" id="modal_selectpersonbtn" class="layui-btn layui-btn-big" style="width:98%; background:#5FB878">确定</button></div>
            </div>
        </div>
    </div>
</div>
<div class="modal_selectperson2" style="display:none">
    <div class="modal_selectpersonbox2">
        <div class="moad_inputbox">
            <input type="text" id="moadConterInput2" readonly value="0" />
            <span onclick="$('#moadConterInput').val($('#moadConterInput').attr('type')=='password' ? '' : '0')"><i class="fa fa-remove-sign"></i></span>
        </div>
        <div class="modal_body">
            <div class="layui-row">
                <div class="layui-col-xs4"><a href="javascript:Counter(7,'#moadConterInput2')">7</a></div>
                <div class="layui-col-xs4"><a href="javascript:Counter(8,'#moadConterInput2')">8</a></div>
                <div class="layui-col-xs4"><a href="javascript:Counter(9,'#moadConterInput2')">9</a></div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs4"><a href="javascript:Counter(4,'#moadConterInput2')">4</a></div>
                <div class="layui-col-xs4"><a href="javascript:Counter(5,'#moadConterInput2')">5</a></div>
                <div class="layui-col-xs4"><a href="javascript:Counter(6,'#moadConterInput2')">6</a></div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs4"><a href="javascript:Counter(1,'#moadConterInput2')">1</a></div>
                <div class="layui-col-xs4"><a href="javascript:Counter(2,'#moadConterInput2')">2</a></div>
                <div class="layui-col-xs4"><a href="javascript:Counter(3,'#moadConterInput2')">3</a></div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs4"><a href="javascript:Counter(0,'#moadConterInput2')">0</a></div>
                <div class="layui-col-xs4"><a href="javascript:Counter('.','#moadConterInput2')">.</a></div>
                <div class="layui-col-xs4"><a href="javascript:Counter('B','#moadConterInput2')"><i class="fa fa-arrow-left"></i></a></div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6"><button type="button" id="modal_selectpersonclosebtn2" class="layui-btn layui-btn-big" style="width:98%; background:#FFF; color:#333; border:1px solid #CCC;">关闭</button></div>
                <div class="layui-col-xs6"><button type="button" id="modal_selectpersonbtn2" class="layui-btn layui-btn-big" style="width:98%; background:#5FB878">确定</button></div>
            </div>
        </div>
    </div>
</div>
<!--餐台选择-->
<style>
    .modal_selecttablebox{}
    .pt_topbarlist{overflow-x: scroll;}
    .pt_menubar{background:#EEE;height:40px;white-space:nowrap;overflow-x:visible;overflow-y:hidden}
    .pt_menuitem{text-align:center;font-size:14px;background:#ECF0F1;display:inline-block;padding:5px 10px;line-height:30px;}
    .pt_menubar .isselect{ background:#5FB878; color:#FFF}
    .pt_tablelist{padding:10px;height:100%;overflow-y:scroll;}
    .pt_tablelist li{width: 31.0%; border: 1px solid #CCC; border-radius:4px; float: left; font-size:12px; text-align: center; margin: 0 5px 5px 0; height: 70px; max-height: 70px; overflow: hidden;display:-webkit-box;display:-webkit-flex;display:flex; -webkit-box-pack:center;-webkit-justify-content:center;justify-content:center;-webkit-box-align:center;-webkit-align-items:center; align-items:center;}
    .pt_tablelist li h3{display: block; margin-bottom: 5px; width: 100%;}
    .pt_tablelist .status_0 { background:#ECF0F1;}
    .pt_tablelist .status_1 { background:#177ABD;color:#FFF}
    .pt_tablelist .status_2 { background:#FE893C;color:#FFF}

    .page_table_list li.isselect a{background:#EEE;color:#000}
</style>
<div class="modal_selecttable" style="display:none">
    <div class="modal_selecttablebox">
        <div class="pt_topbarlist">
            <ul class="pt_menubar">
                {loop $tablepcatelist $row}
                <li class="pt_menuitem" tcid="{$row['id']}"><A href="javascript:fun_selectTablePcate({$row['id']})">{$row['title']}</A></li>
                {/loop}
            </ul>
        </div>
        <div>
            <ul class="pt_tablelist">

            </ul>
        </div>
    </div>
</div>
<!--menumore-->
<style>
    .modal_morebtnbox{ text-align:center;}
    .modal_morebtnbox a{ display:inline-block;width:80px; height:80px; line-height:80px; text-align:center; border:1px solid #CCC; border-radius:4px; font-size:18px;margin:10px;}
</style>
<div class="modal_morebtn" style="display:none">
    <div class="modal_morebtnbox" style="padding:15px;">
        <input type="hidden" id="rowid" value="0"/>
        <a href="javascript:fun_morebtn(0)" class="b1">口味</a>
        <a href="javascript:needPass(1)" class="b2">改价</a>
        <a href="javascript:fun_morebtn(2)" class="b3">上菜</a>
        <a href="javascript:fun_morebtn(3)" class="b4">删除</a>
    </div>
</div>
<!--menumore-->
<style>
    .showtaste{padding: 10px;}
    .showtaste span{ border: 1px solid #CCC; padding: 5px; display: inline-block; margin: 5px; background:#FFF; color: #333;border-radius: 4px}
    .showtaste span.isselect{ background:#01AAED;border-color:#01AAED;color: #FFF;}
</style>
<div class="showtastebox" style="display: none;">
    <DIV class="showtaste"></DIV>
</div>
<!--呼叫服务员-->
<style>
    .modal_servicebox{ text-align:center;}
    .modal_servicebox a{ display:inline-block;width:60px; height:60px; line-height:60px;text-align:center;border:1px solid #CCC;border-radius:4px; font-size:18px;margin:10px;}
</style>
<div class="modal_service" style="display:none">
    <div class="modal_servicebox" style="padding:15px;">
        {if $shop['servicetype']}
        {loop explode('|',$shop['servicetype']) $row}
        <a href="javascript:fun_callservice('{$row}')">{$row}</a>
        {/loop}
        {else}
        <a href="javascript:fun_callservice('呼叫服务员')">呼叫服务员</a>
        {/if}
    </div>
</div>
<script language="javascript">
    window.onresize=function(){
        objectPos();
    }
    $(function() {
        FastClick.attach(document.body);
    });
    layui.use(['layer', 'element','form'], function(){
        var layer = layui.layer
                ,element = layui.element
                ,form = layui.form;
        objectPos();
        fun_statrTable();

        form.on('submit(formDemo)', function(data){
            var tid=parseInt($("#tablebtn").attr("tid"));
            if(tid==0){
                layer.msg("请输入餐桌",{icon:2,time: 2000});
                return false;
            }
            fun_statrTable(tid);
            return false;
        });
    });
    function fun_statrTable(tid){
        tids=tid ? tid : "{php echo $_GPC['selfttableid']}";
        if(!tids)return;
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('phone',array('op'=>'startorder'))}",{tid:tids},function(returnstr){
            layer.close(index2);
            console.log(returnstr);
            var result=eval("("+returnstr+")");
            if(result.success){
                var _isnew=false;
                if(parseInt(result.trade.isaddorder)==0 && parseInt(result.trade.person)==0)_isnew=true;
                OrderStart(_isnew);
                fun_formatMenu(result.table,result.trade,result.goods,result.tradelist);
            }else{
                layer.msg(result.msg,{icon:2,time: 2000});
                return false;
            }
        })
    }
    function fun_formatMenu(table,trade,goods){
        $("#sub_orderid").val(trade.id);
        $("#sub_person").val(trade.person);
        $("#sub_tid").val(table.id);
        $("#count_price").val("￥ "+fee2num(trade.order_fee));
        $("#count_num1").val();
        $("#count_num").val(trade.num);
        $("#count_teafee").val(trade.teafee).attr({"teafee":table.teafee,"perperson":table.perperson});
        $("#count_person").val(trade.person);
        $("#menulist").empty();
        if(!goods)return;
        var key=1;
        for(var i in goods){
            var temp='<tr isnew="false" mid="'+goods[i].id+'" title="'+goods[i].title+'" goodsn="'+goods[i].goodsn+'" gid="'+goods[i].goodid+'" price="'+goods[i].price+'" mprice="'+goods[i].memberprice+'" oprice="'+goods[i].oldprice+'"><td class="index">'+key+'</td><td><span class="til">'+goods[i].title+'</span><div class="goodinfo"><div class="taste">'+goods[i].taste+'</div></div></td><td class="tableNum"><input type="text" class="tnum" value="'+goods[i].num+'"/></td><td class="tprice">'+goods[i].price+'</td><td class="ttotal">'+fee2num(goods[i].total_fee)+'</td><td class="tstatus"><span class="layui-badge layui-bg-orange">下单</span>';
            if(parseInt(goods[i].finishtime))temp+='<span class="layui-badge finish">已上</span>';
            temp+='</td><td><a href="javascript:fun_showbtn(this)" class="layui-btn layui-btn-small">更多</a></td></tr>';
            $("#menulist").append(temp);
            key++;
        }
        count_total();
    }
    function objectPos(){
        var _w=$(window).width();
        var _h=$(window).height();
        var __h=$(".loginbox").height();
        $(".loginbox").css("margin-top",(_h-__h)*0.5);
        $(".goodlistbox").height(_h-110);
    }
    function mdl_selectperson(){
        if(arguments.length>0){
            layer.open({
                type:1,
                title:"输入密码",
                skin:'layui-layer-rim',
                content:$(".modal_selectperson").show(),
                success: function(layero, index){
                    $("#moadConterInput").attr("type","password").val("");
                    $("#modal_selectpersonbtn").bind("click",function(){
                        var num=$('#moadConterInput').val();
                        if(num==0 || num.length<4){
                            layer.msg("请输入密码",{icon:2,time: 2000});
                            return;
                        }
                        $("#mpassword").val(num);
                        layer.close(index);
                    });
                    $("#modal_selectpersonclosebtn").bind("click",function(){
                        layer.close(index);
                    });
                },
                end:function(){
                    $(".modal_selectperson").hide();
                    $("#modal_selectpersonbtn").unbind("click");
                    $("#modal_selectpersonclosebtn").unbind("click");
                }
            });

        }else{
            layer.open({
                type:1,
                title:"选择就餐人数",
                skin:'layui-layer-rim',
                content:$(".modal_selectperson").show(),
                success: function(layero, index){
                    var person=$("#personbtn").attr("person");
                    $("#moadConterInput").attr("type","text").val(person);
                    $("#modal_selectpersonbtn").bind("click",function(){
                        var num=parseInt($('#moadConterInput').val());
                        if(num==0 || isNaN(num)){
                            layer.msg("请输入正确的数字",{icon:2,time: 2000});
                            return;
                        }
                        $("#personbtn").text(num+"人").attr("person",num);
                        layer.close(index);
                    });
                    $("#modal_selectpersonclosebtn").bind("click",function(){
                        layer.close(index);
                    });
                },
                end:function(){
                    $(".modal_selectperson").hide();
                    $("#modal_selectpersonbtn").unbind("click");
                    $("#modal_selectpersonclosebtn").unbind("click");
                }
            });
        }
    }
    function fun_person(){
        layer.open({
            type:1,
            title:"修改就餐人数",
            skin:'layui-layer-rim',
            content:$(".modal_selectperson").show(),
            success: function(layero, index){
                $(".modal_selectperson .teger").show();
                $(".modal_selectperson .float").hide();
                var person=$("#count_person").val();
                $("#moadConterInput").attr("type","text").val(person);
                $("#modal_selectpersonbtn").bind("click",function(){
                    var num=parseInt($('#moadConterInput').val());
                    if(num==0 || isNaN(num)){
                        layer.msg("请输入正确的数字",{icon:2,time: 2000});
                        return;
                    }
                    $("#count_person").val(num);
                    layer.close(index);
                });
                $("#modal_selectpersonclosebtn").bind("click",function(){
                    layer.close(index);
                });
            },
            end:function(){
                $(".modal_selectperson").hide();
                $("#modal_selectpersonbtn").unbind("click");
                $("#modal_selectpersonclosebtn").unbind("click");
            }
        });
    }
    function mdl_selecttable(){
        var _w=$(window).width()-30;
        var _h=$(window).height()-30;
        layer.open({
            type: 1,
            title:0,
            area:[_w+"px",_h+"px"],
            skin: 'layui-layer-rim',
            content:$(".modal_selecttable").show(),
            success: function(layero, index){
                $(".pt_menubar").width(_w-10);
                $(".pt_menubar li").eq(0).find("a").click();
            },
            end:function(){
                $(".modal_selecttable").hide();
                $("#modal_selectpersonbtn").unbind("click");
            }
        });
    }
    function fun_selectTablePcate(pcate){
        $(".pt_menuitem[tcid='"+pcate+"']").addClass("isselect").siblings().removeClass("isselect");
        var pcate=$(".pt_menubar .isselect").attr("tcid");
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('phone',array('op'=>'getpcatetable'))}",{pcate:pcate},function(returnstr){
            layer.close(index2);
            console.log(returnstr);
            var result=eval("("+returnstr+")");
            if(result.success){
                var _h=$(window).height()-$(".pt_menubar").height()-85;
                var _w=$(window).width()-45;
                $(".pt_tablelist").height(_h);
                var list=result.list;
                if(list.length==0){
                    $('.pt_tablelist').text("暂无内容");
                    return;
                }
                $(".pt_tablelist").empty();
                for(var i in list){
                    var temp='<li class="status_'+list[i].status+'" tid="'+list[i].id+'" status="'+list[i].status+'" onclick="fun_selectTable('+list[i].id+')"><div><h3>'+list[i].title+'</h3><div class="pt_time text-center">';
                    switch(parseInt(list[i].status)){
                        case 0:
                            temp+='<span class="layui-badge layui-bg-green">空闲</span>';
                            break;
                        case 1:
                            temp+='<span class="layui-badge layui-bg-cyan">已开台</span>';
                            break;
                        case 2:
                            temp+='<span class="layui-badge layui-bg-blue">已点菜</span>';
                            break;
                        case 3:
                            temp+='<span class="layui-badge layui-bg-orange">预定</span>';
                            break;
                    }
                    if(parseInt(list[i].ispay))temp+=' <span class="layui-badge">已付款</span>';
                    if(parseInt(list[i].ismore))temp+=' <span>拼桌</span>';
                    temp+='</div></div></li>';
                    $(".pt_tablelist").append(temp);
                }
                $(".pt_tablelist").scrollTop(0);
            }else{
                layer.msg(result.msg,{icon:2,time:1000});
                return;
            }
        });
    }
    function fun_selectTable(tid){
        var title=$(".pt_tablelist li[tid='"+tid+"']").find("h3").text();
        $("#tablebtn").attr("tid",tid).text("选择餐台："+title);
        $(".header .title").text(title);
        layer.closeAll();
    }
    function Counter(num,obj){
        var vTecla=num;
        var salida=$(obj);
        if(vTecla=='C'){
            salida.val('0');
            return false;
        }
        if(vTecla=='B'){
            var temp1=salida.val();
            salida.val(temp1.substr(0,temp1.length-1));
            if(obj=="#ppl_input_paidfee")fun_paycount();
            return false;
        }
        if(salida.val().length>8){
            return false;
        }
        if(vTecla=='.'){
            if(salida.val().indexOf('.')>-1){
                salida.val(salida.val());
            }else{
                salida.val(salida.val()+vTecla);
            }
        }else if(vTecla=='0'){
            if(salida.val()==0 && salida.val().length==1){
                salida.val(0);
            }else{
                salida.val(salida.val()+vTecla);
            }
        }else{
            if((salida.val()==0 && salida.val().length==1)){
                salida.val(vTecla);
            }else{
                salida.val(salida.val()+vTecla);
            }
        }
        var temp=salida.val();
        if(temp.indexOf('.')>-1){
            var float=temp.split('.');
            if(float[1].length>2){
                salida.val(float[0]+'.'+float[1].substr(0,2));
            }
        }
    }
    function _getTableTime(timestamp){
        nowTimestamp = Date.parse(new Date());
        nowTimestamp = parseInt(nowTimestamp*0.001)-timestamp
        return parseInt(nowTimestamp/60)+"分钟";
    }
    function OrderStart(isnew){
        if(isnew){
            $("#count_person").click();
        }
        $(".loginbox").hide();
        $(".orderbox").show();
        $(".header").show();
        $("footer").show();
        var _h=$(window).height()-30;
        $(".countbar").height(_h).css("top",_h-20);
        $(".menulistbox").height(_h-90);
        if($(".goodpcatelist ul li").size())$(".goodpcatelist ul li").eq(0).click();
    }
    function fun_mainFun(index){
        if($(".mainmenubtn li[cid="+index+"]").hasClass("isselect"))return;
        $(".mainmenubtn li[cid="+index+"]").addClass("isselect").siblings().removeClass("isselect");
        layer.closeAll();
        if(index==0){
            //$(".mianpage").eq(0).show().siblings().hide();
        }else if(index==1){
            //$(".mianpage").eq(1).show().siblings().hide();
        }else if(index==2){
            layer.open({
                type:1,
                title:0,
                area:"400px",
                skin:'layui-layer-rim',
                content:$(".modal_service").show(),
                end:function(){
                    $(".modal_service").hide();
                }
            });
        }else if(index==3){
            needPass(2);
        }else if(index==4){
            layer.confirm('确认退出？', function(){
                var index2=layer.load(1, {shade: [0.1,'#fff']});
                $.post("{php echo $this->createMobileUrl('phone',array('op'=>'logout'))}",{},function(returnstr){
                    layer.close(index2);
                    var result=eval("("+returnstr+")");
                    if(result.success){
                        location.reload();
                    }else{
                        layer.msg(result.msg,{icon:2,time: 2000});
                        return;
                    }
                });
            });
        }
    }

    function fun_selectgoodpcate(pcate){
        $(".goodpcatelist li[gcid='"+pcate+"']").addClass("isselect").siblings().removeClass("isselect");
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('phone',array('op'=>'getpcategood'))}",{pcate:pcate},function(returnstr){
            layer.close(index2);
            //console.log(returnstr);
            var result=eval("("+returnstr+")");
            if(result.success){
                var list=result.list;
                $(".goodlistbox").empty();
                if(list.length==0)return;
                for(var i in list){
                    var temp='<li gid="'+list[i].id+'" title="'+list[i].title+'" goodsn="'+list[i].goodsn+'" store="'+list[i].store+'" price="'+list[i].marketprice+'" mprice="'+list[i].memberprice+'" pcate="'+pcate+'"><A><h3>'+list[i].title+'</h3><p>'+list[i].goodsn+'</p><div onClick="fun_addgood('+list[i].id+')"><span>￥'+list[i].marketprice+'</span><span class="pull-right"><i class="fa fa-shopping-cart"></i></span></div></A></li>';
                    $(".goodlistbox").append(temp);
                }
            }else{
                layer.msg(result.msg,{icon:2,time:1000});
                return;
            }
        })
    }
    function fun_showmenu(){
        var top=parseInt($(".countbar").css("top").replace("px"));
        if(top<=30){
            var _h=$(".countbar").height()-20;
            Let('.countbar')
                    .set("top",_h)
                    .end(function (){
                        $(".countbar_menu").hide();
                    });
        }else{
            $(".countbar_menu").show();
            Let('.countbar')
                    .set("top",30)
                    .end();
        }
    }

    function count_total(){
        var num=0;
        var totalfee=0;
        $("#menulist tr").each(function(index, element) {
            num+=parseInt($(this).find(".tnum").val());
            totalfee+=parseInt(parseFloat($(this).find(".ttotal").text())*100);
            $(this).find("a").attr("href","javascript:fun_showbtn("+index+")");
        });
        var num1=$("#menulist .finish").size();
        var perperson=parseInt(parseFloat($("#count_teafee").attr("perperson"))*100);
        var atless=parseInt(parseFloat($("#count_teafee").attr("teafee"))*100);
        var person=parseInt($("#count_person").val());
        var teafee=((perperson*person+atless)*0.01).toFixed(2);
        $("#count_price").val("￥ "+(totalfee*0.01).toFixed(2));
        $("#count_num1").val(num1);
        $("#count_num").val(num);
        $("#count_teafee").val(teafee);
    }
    function fun_morebtn(types){
        var rowid=$("#rowid").val();
        layer.closeAll();
        switch(types){
            case 0:
                layer.open({
                    type: 1,
                    title:"选择口味",
                    area:'440px',
                    skin: 'layui-layer-rim',
                    content:$(".modal_taste").show(),
                    btn:['确认','取消'],
                    btn1:function(index,layero){
                        var temp=[];
                        $(".modal_taste .isselect").each(function(index, element) {
                            temp.push($(this).text());
                        });
                        if(!$("#menulist tr:eq("+rowid+")").find(".taste").size()){
                            $("#menulist tr:eq("+rowid+")").find(".goodinfo").append("<span class='taste'>"+temp.join(',')+"</div>");
                        }else{
                            $("#menulist tr:eq("+rowid+")").find(".taste").text(temp.join(','));
                        }
                        layer.close(index);

                    },
                    success: function(layero, index){
                        var taste = $("#menulist tr:eq("+rowid+")").find(".taste").text();
                        if(taste.length){
                            var temp=taste.split(",");
                            for(var i=0;i<temp.length;i++){
                                $(".modal_taste span[taste='"+temp[i]+"']").addClass("isselect");
                            }
                        }
                        $(".modal_taste span").bind("click",function(){
                            if($(this).hasClass("isselect")){
                                $(this).removeClass("isselect");
                            }else{
                                $(this).addClass("isselect");
                            }
                        });
                    },
                    end:function(){
                        $(".modal_taste").hide();
                        $(".modal_taste span").unbind("click");
                        $(".modal_taste span").removeClass("isselect");
                    }
                });
                break;
            case 1:
                var target=$("#menulist tr:eq("+rowid+")");
                var oldprice=target.attr("oprice");
                var nowprice=target.attr("price");
                layer.open({
                    type:1,
                    title:"修改价格，当前价格：￥"+nowprice+"；原价：￥"+oldprice,
                    area:"400px",
                    skin:'layui-layer-rim',
                    content:$(".modal_selectperson2").show(),
                    success: function(layero, index){
                        $('#moadConterInput2').val("0");
                        $("#modal_selectpersonbtn2").bind("click",function(){
                            var price=parseFloat($('#moadConterInput2').val());
                            if(price==0 || isNaN(price)){
                                layer.msg("请输入正确的数字",{icon:2,time: 2000});
                                return;
                            }
                            target.attr("price",price.toFixed(2));
                            target.find(".tprice").text(price.toFixed(2));
                            var number=parseInt(target.find(".tnum").val());
                            var totalfee=fee2num(price*100*number);
                            target.find(".ttotal").text(totalfee);
                            count_total();
                            layer.close(index);
                        });
                        $("#modal_selectpersonclosebtn2").bind("click",function(){
                            layer.closeAll();
                        });
                    },
                    end:function(){
                        $("#modal_selectperson2").hide();
                        $("#modal_selectpersonbtn2").unbind("click");
                        $("#modal_selectpersonclosebtn2").unbind("click");
                    }
                });
                break;
            case 2:
                var target=$("#menulist tr:eq("+rowid+")");
                var mid=target.attr("mid");
                if(!mid){
                    layer.msg("该商品还没有下单",{icon:2,time:1000});
                    return;
                }
                if(target.find(".finish").size()){
                    layer.msg("不能重复上菜",{icon:2,time:1000});
                    return;
                }
                layer.confirm('确认上菜？', {icon:3,title:"订单修改提示"}, function(index){
                    layer.close(index);
                    var index2=layer.load(1, {shade: [0.1,'#fff']});
                    $.post("{php echo $this->createMobileUrl('phone',array('op'=>'finishgood'))}",{mid:mid},function(returnstr){
                        layer.close(index2);
                        console.log(returnstr);
                        var result=eval("("+returnstr+")");
                        if(result.success){
                            if(!target.find(".finish").size())target.find(".tstatus").append('<span class="layui-badge finish">已上</span>');
                            layer.msg("操作成功",{icon:1,time:1000});
                            count_total();
                        }else{
                            layer.msg(result.msg,{icon:2,time:1000});
                            return;
                        }
                    });
                });
                break;
            case 3:
                var target=$("#menulist tr:eq("+rowid+")");
                if(parseInt(target.attr("mid"))){
                    layer.confirm('该商品已下单，请确认是否已制作。点击[确认]进行删除', {icon:3,title:"订单修改提示"}, function(index){
                        $("#menulist tr:eq("+rowid+")").remove();
                        count_total();
                        layer.close(index);
                    });
                }else{
                    $("#menulist tr:eq("+rowid+")").remove();
                    count_total();
                }
                break;
        }
    }
    function fun_munebtn_submitorder(){
        if(!$("#menulist tr").size()){
            layer.msg("请先添加商品",{icon:2,time:1000});
            return;
        }
        var orderid=$("#sub_orderid").val();
        var person=$("#count_person").val();

        var param=[];
        $("#menulist tr").each(function(index, element) {
            var id=$(this).attr("mid")!="undefined" ? $(this).attr("mid") : "";
            var goodid=$(this).attr("gid");
            var price=$(this).attr("price");
            var mprice=$(this).attr("mprice");
            var oprice=$(this).attr("oprice");
            var title=$(this).attr("title");
            var goodsn=$(this).attr("goodsn");
            var num=$(this).find(".tnum").val();
            var fee=$(this).find(".ttotal").text().replace("￥","");
            var taste=$(this).find(".taste").text();
            var ispack=$(this).find(".ispack").size();
            var temp=id+"|"+goodid+"|"+goodsn+"|"+title+"|"+price+"|"+mprice+"|"+oprice+"|"+num+"|"+fee+"|"+ispack+"|"+taste;
            param.push(temp);
        });
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        $.post("{php echo $this->createMobileUrl('phone',array('op'=>'submitorder'))}",{param:param,orderid:orderid,person:person},function(returnstr){
            console.log(returnstr);
            var result=eval("("+returnstr+")");
            if(result.success){
                layer.msg("下单成功",{icon:1,time:1000},function(){
                    var index2=layer.load(1, {shade: [0.1,'#fff']});
                    var tid=$("#sub_tid").val();
                    $.post("{php echo $this->createMobileUrl('phone',array('op'=>'startorder'))}",{tid:tid},function(returnstr){
                        layer.close(index2);
                        var result=eval("("+returnstr+")");
                        if(result.success){
                            fun_formatMenu(result.table,result.trade,result.goods,result.tradelist);
                        }else{
                            layer.msg(result.msg,{icon:2,time: 2000});
                            return;
                        }
                    });
                });

            }else{
                layer.close(index2);
                layer.msg(result.msg,{icon:2,time:1000});
                return;
            }

        });
    }
    function needPass(types){
        layer.open({
            type:1,
            title:"请输短密码",
            area:"400px",
            skin:'layui-layer-rim',
            content:$(".modal_selectperson").show(),
            success: function(layero, index){
                $("#moadConterInput").attr("type","password").val("");
                var shortpass="{$_GPC['shortpass']}";
                $("#modal_selectpersonbtn").bind("click",function(){
                    var num=$('#moadConterInput').val();
                    if(num!=shortpass){
                        layer.msg("密码错误",{icon:2,time: 2000});
                        return;
                    }
                    layer.close(index);
                    switch(types){
                        case 1:
                            fun_morebtn(1);
                            break;
                        case 2:
                            var index2=layer.load(1, {shade: [0.1,'#fff']});
                            $.post("{php echo $this->createMobileUrl('phone',array('op'=>'clearorderid'))}",{},function(returnstr){
                                location.reload();
                            });
                            break;
                    }
                });
                $("#modal_selectpersonclosebtn").bind("click",function(){
                    layer.close(index);
                });

            },
            end:function(){
                $(".modal_selectperson").hide();
                $("#modal_selectpersonbtn").unbind("click");
                $("#modal_selectpersonclosebtn").unbind("click");
            }
        });
    }
    function fun_callservice(txt){
        var timestamp = parseInt(Date.parse(new Date())*0.001);
        var oldTime=parseInt($(".modal_servicebox").attr("time"));
        if(timestamp-oldTime<60*1){
            layer.msg("呼叫过于频繁，请稍后再试",{icon:2,time: 2000});
            return;
        }
        var index2=layer.load(1, {shade: [0.1,'#fff']});
        var tid=$("#sub_tid").val();
        $.post("{php echo $this->createMobileUrl('phone',array('op'=>'callsevice'))}",{tid:tid,txt:txt},function(returnstr){
            layer.closeAll();
            var result=eval("("+returnstr+")");
            if(result.success){
                $(".modal_servicebox").attr("time",timestamp);
                layer.msg("呼叫成功",{icon:1,time: 1500});
            }else{
                layer.msg(result.msg,{icon:2,time: 2000});
                return;
            }
        });
    }
</script>
{/if}